package com.baiye.template.dao;

import com.baiye.template.pojo.MyFile;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author GUOZHIPENG
 * @version 1.0
 * @date 2021/9/9 18:06
 */
@Repository
public interface FileDao {
    @Select({"<script>" +
            "select * from file " +
            " <where> " +
//            "<if test='start!=null and size !=null'>id >=( select id from file order by id limit #{start},1 )</if>"+
            " <if test='file.id != null'>AND id=#{file.id}</if> " +
            " <if test='file.name != null'>AND name=#{file.name}</if> " +
            " <if test='file.userId != null'> AND user_id=#{file.userId}</if> " +
            " <if test='file.creatTime != null'> AND creat_time &gt; #{file.creatTime}</if> " +
            " </where> " +
            "</script>"})
    List<MyFile> getFile(@Param("file") MyFile myFile, @Param("start")int start, @Param("size")Integer pageSize);

    @Insert("insert into file(name,user_id,url,creat_time) values(#{name},#{userId},#{url},#{creatTime})")
    int saveFile(MyFile file);
}
